/**
 * Created by cennavi on 2018/7/6.
 */
import MYCONF from '../myconf';
import DateTimeHelper from '../util/datetime-helper';
export default class UbtrafficViewController{
  constructor(_view){
    this._view = _view;
  }

  //获取城市画像左侧数据
  getRoadData(){
    let url = MYCONF.service.totalIndexAddress+DateTimeHelper.getCurDateNow();
    this._view.$http.get(url).then(
      response =>{
        response = response.body;
        let arrs = response.result;
        let obj = {};
        arrs.forEach(function (item) {
          if(item.code === '620602'){   //620602代表凉州区
            obj = item;
          }
        })
        this._view.totalIndex = obj;
      },response =>{

      }
    );
  }
  getIndexData(){
    let url = MYCONF.service.roadIndexAddress+DateTimeHelper.getCurDateNow();
    this._view.$http.get(url).then(
      response => {
        response = response.body;
        this._view.roadIndexList = response.result;
      },response =>{

      }
    );
  }

  getTodayChartsData(){    //今日指数
    let url = MYCONF.service.indexTodayChartsAddress+DateTimeHelper.getCurDateNow()+'?codes[]=620600';
    this._view.$http.get(url).then(
      response => {
        response = response.body;
        this._view.todayIndexData = response.result[0].data;
      },response =>{

      }
    );
  }

  getYestodayChartsData(){   //昨日指数
    let url = MYCONF.service.indexYestodayChartsAddress+DateTimeHelper.getCurDateNow()+'?cityCode=620600&indexType=01&compareType=01&granularity=hour';
    this._view.$http.get(url).then(
      response => {
        response = response.body;
        this._view.yestodayIndexData = response.result.yesterday;
      },response =>{

      }
    );
  }

  getLastweekChartsData(){   //上周今日指数
    let url = MYCONF.service.indexYestodayChartsAddress+DateTimeHelper.getCurDateNow()+'?cityCode=620600&indexType=01&compareType=02&granularity=hour';
    this._view.$http.get(url).then(
      response => {
        response = response.body;
        this._view.lastWeekIndexData = response.result.lastweek;

      },response =>{

      }
    );
  }




}
